<?php

namespace S\WeChat\Exception;

/**
 * 内部异常
 *
 * @package \Exception
 */
class Internal extends Abstraction
{
    const CODE_CODE_OVER_RANGE               = '0001';
    const CODE_BEFORE_THROW_ERROR            = '0002';
    const CODE_REQUIRE_REPLACING             = '0003';
    const CODE_TOKEN_EXPIRES_TOO_SHORT       = '0004';
    const CODE_TOKEN_CACHED_FAIL             = '0005';
    const CODE_XML_PARSE_ERROR               = '0006';
    const CODE_CONF_FORMAT_ERROR             = '0007';
    const CODE_CONF_ACCOUNT_UNDEFINED        = '0008';
    const CODE_CONF_ACCOUNT_OPTION_UNDEFINED = '0008';
    const CODE_STORING_CACHE_TYPE_ERROR      = '0009';
    const CODE_CONF_OPT_MUST_BE_ARRAY        = '0010';
    const CODE_CONF_OPT_MUST_NOT_BE_ARRAY    = '0011';
    const CODE_MSG_PARAM_UNDEFINED           = '0012';
    const CODE_MSG_CRYPT_AES_KEY_ERROR       = '0013';
    const CODE_APP_OPT_EMPTY                 = '0014';

    protected function getCodeMessages()
    {
        return [
            self::CODE_CODE_OVER_RANGE               => '错误码只能在3100000至3999999之间(当前为@code@)',
            self::CODE_BEFORE_THROW_ERROR            => '方法$this->beforeThrow()必须返回(bool)true.',
            self::CODE_REQUIRE_REPLACING             => '错误消息中的@replacing@必须被设置',
            self::CODE_TOKEN_EXPIRES_TOO_SHORT       => '设置令牌剩余有效时间必须大于@safety@秒(当前@expires@秒)',
            self::CODE_TOKEN_CACHED_FAIL             => '令牌存储失败',
            self::CODE_XML_PARSE_ERROR               => 'XML解析错误',
            self::CODE_CONF_FORMAT_ERROR             => '配置文件读取错误(@option@@@chain@)',
            self::CODE_CONF_ACCOUNT_UNDEFINED        => '公众号@account@的配置未定义',
            self::CODE_CONF_ACCOUNT_OPTION_UNDEFINED => '公众号配置@option@未定义',
            self::CODE_STORING_CACHE_TYPE_ERROR      => '存储时缓存类型只能是@types@之一(@type_passed@被传入)',
            self::CODE_CONF_OPT_MUST_BE_ARRAY        => '配置项@option@必须是数组',
            self::CODE_CONF_OPT_MUST_NOT_BE_ARRAY    => '配置项@option@不能是数组',
            self::CODE_MSG_PARAM_UNDEFINED           => '消息的@param@未设置',
            self::CODE_MSG_CRYPT_AES_KEY_ERROR       => 'EncodingAESKey长度错误',
            self::CODE_APP_OPT_EMPTY                 => '公众号配置不能为空',
        ];
    }

    protected function getCodePrefix()
    {
        return self::_CODE_PREFIX_DAO_INTERNAL;
    }

    protected function beforeThrow()
    {
        return true;
    }
}